package com.zhaojiadi.singleton;

import java.util.Objects;

/**
 * @Description:双重锁是方法级锁的优化，减少获取实例耗时
 */
public class Singleton_05 {
    private static volatile Singleton_05 instance;

    private Singleton_05() {
    }

    public static Singleton_05 getInstance(){
        if(Objects.nonNull(instance)) return instance;
        synchronized (Singleton_05.class){
            if(Objects.isNull(instance)){//继续判断
                instance=new Singleton_05();
            }
        }
        return instance;
    }
}
